package utils

import (
	"github.com/gin-contrib/cache/persistence"
	"github.com/go-resty/resty/v2"
	"net/http"
	"time"
)

var client *resty.Client

func init() {
	// 创建 Resty 客户端
	client = resty.New()
	// 设置连接池参数
	client.SetTimeout(5 * time.Second)              // 设置超时时间
	client.SetRetryCount(3)                         // 设置重试次数
	client.SetRetryWaitTime(500 * time.Millisecond) // 设置重试等待时间
	client.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36")
	client.SetTransport(&http.Transport{
		MaxIdleConns:        100,              // 设置最大空闲连接数
		MaxIdleConnsPerHost: 20,               // 设置每个主机的最大空闲连接数
		IdleConnTimeout:     30 * time.Second, // 设置空闲连接超时时间
	})
}

func GetClient() *resty.Client {
	return client
}

var CacheStore persistence.CacheStore = persistence.NewInMemoryStore(time.Minute * 2)
